package de.koller.million.render.obj.base;

import de.koller.million.render.RenderRoot;
import de.koller.million.render.obj.IRenderGL;
import de.koller.oceanFramework.math.Vec3;
import org.lwjgl.opengl.GL11;

public class Rect3D implements IRenderGL {
	
	private final RenderRoot rroot;
	private float w, h;

	public Rect3D( RenderRoot rroot, float w, float h ) {
		this.w = w;
		this.h = h;
		this.rroot = rroot;
	}

	@Override
	public void renderThis() {
//		GL11.glColor3f( 1, 1, 1 );
		
		Vec3 normal = new Vec3( 0, 0, 1 );
		Vec3 pos = new Vec3();
//		int light = 0xffffffff;
		
//		FloatBuffer b = BufferUtils.createFloatBuffer( 16 );
//		GL11.glGetFloat( GL11.GL_MODELVIEW_MATRIX, b );
//		double[] mm = new double[16];
//		for( int i = 0; i < 16; i++ )
//			mm[i] = b.get( i );
		
		GL11.glBegin( GL11.GL_QUADS );
			GL11.glNormal3d( normal.getX(), normal.getY(), normal.getZ() );
			
			pos.set( -w/2, -h/2, 0 );
//			light = rroot.envi.getLight( pos, normal, mm );
//			GL11.glColor3f( ColorIntUtil.getRValueF( light ), ColorIntUtil.getGValueF( light ), ColorIntUtil.getBValueF( light ) );
			GL11.glTexCoord2f( 0, h/w );
			GL11.glVertex3d( pos.getX(), pos.getY(), pos.getZ() );
			
			pos.set( +w/2, -h/2, 0 );
//			light = rroot.envi.getLight( pos, normal, mm );
//			GL11.glColor3f( ColorIntUtil.getRValueF( light ), ColorIntUtil.getGValueF( light ), ColorIntUtil.getBValueF( light ) );
			GL11.glTexCoord2f( 1, h/w );
			GL11.glVertex3d( pos.getX(), pos.getY(), pos.getZ() );
			
			pos.set( +w/2, +h/2, 0 );
//			light = rroot.envi.getLight( pos, normal, mm );
//			GL11.glColor3f( ColorIntUtil.getRValueF( light ), ColorIntUtil.getGValueF( light ), ColorIntUtil.getBValueF( light ) );
			GL11.glTexCoord2f( 1, 0 );
			GL11.glVertex3d( pos.getX(), pos.getY(), pos.getZ() );
			
			pos.set( -w/2, +h/2, 0 );
//			light = rroot.envi.getLight( pos, normal, mm );
//			GL11.glColor3f( ColorIntUtil.getRValueF( light ), ColorIntUtil.getGValueF( light ), ColorIntUtil.getBValueF( light ) );
			GL11.glTexCoord2f( 0, 0 );
			GL11.glVertex3d( pos.getX(), pos.getY(), pos.getZ() );
		GL11.glEnd();
	}

	public void set( float w, float h ) {
		this.w = w;
		this.h = h;
	}
	
}
